package org.kealinghornets.jchuah.myapplication;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Toast;


public class MyActivity2 extends Activity {
    int progress = 0;

    public void OnandroidPush(final View viewandroidbuttonpush) {
        final Animation fade_out_animation2 = AnimationUtils.loadAnimation(this, R.anim.fade_out2);
        viewandroidbuttonpush.startAnimation(fade_out_animation2);
        Toast.makeText(this, "You Lose", Toast.LENGTH_SHORT).show();


        startActivity(new Intent(this, MyActivity2.class));
    }

    public void OnspecialPush(final View viewspecialbuttonpush) {
        progress = progress + 1;
        Log.d("org.kealinghornets.jchuah.myapplication", "button pushed");
        Log.d("org.kealinghornets.jchuah.myapplication", "num clear begin");


        final Animation fade_out_animation = AnimationUtils.loadAnimation(this, R.anim.fade_out);
        fade_out_animation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
                viewspecialbuttonpush.setEnabled(false);
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                viewspecialbuttonpush.setEnabled(true);
                Log.d("buttonpush", "id: " + viewspecialbuttonpush.getId());
                viewspecialbuttonpush.setAlpha(0);
                viewspecialbuttonpush.clearAnimation();
            }

            @Override
            public void onAnimationRepeat(Animation animation) {


            }
        });
        Animation fade_in_animation = AnimationUtils.loadAnimation(this, R.anim.fade_in);
        Log.d("org.kealinghornets.jchuah.myapplication", viewspecialbuttonpush.getAlpha() + "");
        if (viewspecialbuttonpush.getAlpha() == 1) {
            Log.d("org.kealinghornets.jchuah.myapplication", "fade out");

            viewspecialbuttonpush.startAnimation(fade_out_animation);
        } else {
            Log.d("org.kealinghornets.jchuah.myapplication", "fade in");
            viewspecialbuttonpush.startAnimation(fade_in_animation);
            viewspecialbuttonpush.setAlpha(1);

        }
        if (progress == 2) {
            Toast.makeText(this, "You Win!!", Toast.LENGTH_SHORT).show();




            startActivity(new Intent(this,MyActivity3.class));

        }
    }

    public void OnrainbowPush(final View viewcoloredbuttonpush) {
        Log.d("org.kealinghornets.jchuah.myapplication", "button pushed");
        Log.d("org.kealinghornets.jchuah.myapplication", "num clear begin");


        final Animation fade_out_animation = AnimationUtils.loadAnimation(this, R.anim.fade_out);
        fade_out_animation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
                viewcoloredbuttonpush.setEnabled(false);
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                viewcoloredbuttonpush.setEnabled(true);
                Log.d("buttonpush", "id: " + viewcoloredbuttonpush.getId());
                viewcoloredbuttonpush.setAlpha(0);
                viewcoloredbuttonpush.clearAnimation();
            }

            @Override
            public void onAnimationRepeat(Animation animation) {


            }
        });
        Animation fade_in_animation = AnimationUtils.loadAnimation(this, R.anim.fade_in);
        Log.d("org.kealinghornets.jchuah.myapplication", viewcoloredbuttonpush.getAlpha() + "");
        if (viewcoloredbuttonpush.getAlpha() == 1) {
            Log.d("org.kealinghornets.jchuah.myapplication", "fade out");

            viewcoloredbuttonpush.startAnimation(fade_out_animation);
        } else {
            Log.d("org.kealinghornets.jchuah.myapplication", "fade in");
            viewcoloredbuttonpush.startAnimation(fade_in_animation);
            viewcoloredbuttonpush.setAlpha(1);

        }


        String coloredbuttonName = getResources().getResourceEntryName(viewcoloredbuttonpush.getId());
        int coloredbuttonRow = Integer.parseInt(coloredbuttonName.charAt(11) + "");
        int coloredbuttonColumn = Integer.parseInt(coloredbuttonName.charAt(12) + "");
        Log.d("coloredbutton", "row: " + coloredbuttonRow + "column:" + coloredbuttonColumn);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_activity2);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.my_activity2, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}
